import numpy as np

data = [
    [1, 2, 3],
    [4, 5, 6]
]
# 行优先
arr1 = np.array(data, order="C")
print(arr1)
print("---------------")
print(arr1.flags)
# 列优先
arr2 = np.array(data, order="F")
print(arr2)
print("------------------")
print(arr2.flags)

print("--------------------")
import numpy as np

# - arange()：类似range的序列数组   [start, stop)
arr1 = np.arange(10)
print(arr1)
arr1 = np.arange(1, 10)
print(arr1)
arr1 = np.arange(1, 10, 3)
print(arr1)

# - zeros()：全零数组
# - ones()：全1数组
arr2 = np.ones(10) * 255
print(arr2)
arr2 = np.ones((2, 3))
print(arr2)

# - empty()：未初始化数组【随机垃圾值】
arr3 = np.empty((10, 10))
print(arr3)

# - full()：填充指定值的数组
arr4 = np.full((2, 3), 66)
print(arr4)

# - linespace(): 等差序列
# 等差序列 和 range序列一样吗？
arr5 = np.linspace(0, 10, 5)
print(arr5)

import numpy as np

one_dim = np.array([7, 2, 9, 10])
print("一维数组\n", one_dim)

two_dim = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
print("二维数组\n", two_dim)

three_dim = np.array([
                     [[1, 2, 3, 4], [5, 6, 7, 8]],
                     [[1, 2, 3, 4], [5, 6, 7, 8]]
                     ])
print("三维数组\n", three_dim)

print("==" * 40)

arr1 = np.zeros((4,))
print("一维数组\n", arr1)
arr2 = np.zeros((2, 3))
print("二维数组\n", arr2)
arr3 = np.zeros((4, 3, 2))
print("三维数组\n", arr3)


import numpy as np

one_dim = np.array([7, 2, 9, 10])
print("一维数组\n", one_dim)
print("访问元素\n", one_dim[0], one_dim[1])
print("切片\n", one_dim[::-1], one_dim[0:3])

import numpy as np

two_dim = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
print("二维数组\n", two_dim)
print("访问元素")
print(two_dim[0], two_dim[1])
print(two_dim[0][1], two_dim[0, 2])
print("切片")
print(two_dim[0:2])
print(two_dim[0:2, 1])
print(two_dim[0, :])    # 轴0 垂直方向 控制行数
print(two_dim[:, 1])    # 轴1 水平方向 控制列数


import numpy as np

two_dim = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
print("二维数组\n", two_dim)
print("访问元素")
print(two_dim[0], two_dim[1])
print(two_dim[0][1], two_dim[0, 2])
print("切片")
print(two_dim[0:2])
print(two_dim[0:2, 1])
print(two_dim[0, :])    # 轴0 垂直方向 控制行数
print(two_dim[:, 1])    # 轴1 水平方向 控制列数

import numpy as np
arr = np.array([[1, 2, 3, 4, 5],
                [2, 3, 4, 5, 6]], dtype=np.int8)
print("形状", arr.shape)
print("元素总个数", arr.size)
print("维度数量", arr.ndim)
print("数组类型", arr.dtype)
print("元素字节数", arr.itemsize)
